﻿
using Engine;
using Game;

namespace Mekiasm
{
    public class GasTankWidget : BaseEnergyWidget
    {
        public ComponentEnergyMachine Component;
        public MekInventorySlotWidget inventory;
        public FluidBaseProgress FluidBaseProgress;
        public string containerName;
        public ComponentEnergyMachine.Slot Slot;
        public StackPanelWidget mStackCenter = new StackPanelWidget() { Direction = LayoutDirection.Vertical, HorizontalAlignment = WidgetAlignment.Center, VerticalAlignment = WidgetAlignment.Center };
        public GasTankWidget(ComponentEnergyMachine machine, ComponentMiner componentMiner) : base(componentMiner)
        {
            Component = machine;
            Slot = Component.Slots[0];
            FluidBaseProgress = new FluidBaseProgress(new Vector2(40, 120), Slot);
            inventory = new MekInventorySlotWidget() { Size = new Vector2(48, 48), BevelColor = Color.Red };
            inventory.AssignInventorySlot(machine, 0);
            inventory.ConfigSlotMode(componentMiner);
            mStackCenter.Children.Add(inventory);
            CanvasWidget canvasWidget = new CanvasWidget() { Size = new Vector2(60, 20) };
            mStackCenter.Children.Add(canvasWidget);
            CanvasMain.Children.Add(mStackCenter);
            CanvasMain.Children.Add(FluidBaseProgress);
            FluidBaseProgress.Margin = new Vector2(40, 0);
            setTitle("气体储罐");
            mekProgress.IsVisible = false;
        }

        public override void Update()
        {
            int c = Terrain.ExtractContents(Slot.FuelValue);
            if (c == 0) { containerName = "无"; }
            else containerName = BlocksManager.Blocks[c].GetDisplayName(null, Slot.FuelValue);
            SetPowerProgress((float)Component.Power / Component.MaxPower);
            SetLeftBottomMoreInfo($"装载气体：{containerName}\n气体储存:{ILibrary.FormatGas(Slot.FuelAmount)}\n最大储存:{ILibrary.FormatGas(Slot.FuelCapacity)}");
            FluidBaseProgress.SetProgress((float)Component.Slots[0].FuelAmount / Component.Slots[0].FuelCapacity);
        }
    }
}
